package com.junmiao.A.postProcess;

import com.junmiao.A.stockModel.ShareHolder;
import com.junmiao.A.stockModel.SinaStockBean;

public class SinaStockPostProcess {

	public static SinaStockBean postSinaStockBeanProcess(String resp) {

		SinaStockBean ssb = new SinaStockBean();

		int b = resp.indexOf("title");
		int eb = resp.indexOf("_沪深行情");

		if (b != -1) {

			String stock = resp.substring(b + 6, eb);
			String stockNo = stock.substring(stock.length() - 7,
					stock.length() - 1);
			String stockName = stock.substring(0, stock.length() - 8);

			int t = resp.indexOf("增减状况");

			if (t != -1) {

				String now = resp.substring(t + 25);

				for (int i = 0; i < 10; i++) {
					ShareHolder sh = new ShareHolder();
					for (int j = 0; j < 4; j++) {
						int f = now.indexOf("td");
						String elem = "no";
						if (f > 0) {
							String next = now.substring(f);
							int g = next.indexOf(">");
							String cur = next.substring(g);
							int h = cur.indexOf("<");
							if (h > 1) {
								elem = cur.substring(1, h);
								now = cur.substring(6 + h);
							}

						}

						if (j % 4 == 0) {
							sh.setName(elem);
						} else if (j % 4 == 1) {
							sh.setHolderAmount(elem);
						} else if (j % 4 == 2) {
							sh.setOperation(elem);
						} else if (j % 4 == 3) {
							sh.setDelta(elem);
						}

					}

					ssb.getShareHolders().add(sh);

				}

			}

			ssb.setStockNo(stockNo);
			ssb.setStockName(stockName);
		}
		
		return ssb;
	}
}
